package io.renren.controller;

import io.renren.annotation.LoginUser;
import io.renren.common.constant.Constant;
import io.renren.common.page.PageData;
import io.renren.common.utils.Result;
import io.renren.dto.FoodmxDTO;
import io.renren.entity.UserEntity;
import io.renren.service.FoodmxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;


/**
 * 辅材库明细表
 *
 * @author 罗胜平 781757616@qq.com
 * @since 1.0.0 2019-11-22
 */
@RestController
@RequestMapping("api/foodmx")
@Api(tags="辅材库明细表")
public class FoodmxController {
    @Autowired
    private FoodmxService foodmxService;

    @GetMapping("page")
    @ApiOperation("分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
        @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String")
    })
    public Result<PageData<FoodmxDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<FoodmxDTO> page = foodmxService.page(params);

        return new Result<PageData<FoodmxDTO>>().ok(page);
    }

    @GetMapping("{id}")
    @ApiOperation("信息")
    public Result<FoodmxDTO> get(@PathVariable("id") Long id){
        FoodmxDTO data = foodmxService.get(id);

        return new Result<FoodmxDTO>().ok(data);
    }
    @GetMapping("saveFoodmx")
    @ApiOperation("辅材信息入库")
    public Result saveFoodmx(Long id,long canteenId ){
         foodmxService.saveFoodmx(id,canteenId);

        return new Result();
    }

    @GetMapping("selectAllFoodmx")
    @ApiOperation("查询库中所有商品")
    public Result<List<FoodmxDTO>> selectAllFoodmx(String foodName,String variety,int sign,Long orderId, @LoginUser UserEntity entity){
        List<FoodmxDTO> data = foodmxService.selectAllFoodmx(foodName,variety,sign,orderId,entity);
        return new Result<List<FoodmxDTO>>().ok(data);
    }
}